<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>显示所有比赛项目信息</title>
    <script src="js/axios-0.21.0.js"></script>
    <script src="js/vue.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>

<body>
<div id="app">
    <el-row>
        <el-col :span="6">
            <span style="font-size:30px">高校运动会管理系统</span>
        </el-col>
        <el-col :span="18">
            <el-menu :default-active="activeIndex" mode="horizontal">
                <el-menu-item index="1">
                    <el-link href="index.html">首页</el-link>
                </el-menu-item>
                <el-submenu index="2">
                    <template slot="title">运动员管理</template>
                    <el-menu-item index="2-1">
                        <el-link
                                :href="'athletesList.html?role='+role">运动员列表
                        </el-link>
                    </el-menu-item>
                    <el-menu-item index="2-2" v-if="role==0">
                        <el-link
                                :href="'athletesAdd.html?role='+role">添加运动员
                        </el-link>
                    </el-menu-item>
                </el-submenu>
                <el-submenu index="3">
                    <template slot="title">裁判管理</template>
                    <el-menu-item index="3-1">
                        <el-link
                                :href="'judgeList.html?role='+role">裁判列表
                        </el-link>
                    </el-menu-item>
                    <el-menu-item index="3-2" v-if="role==0">
                        <el-link
                                :href="'judgeAdd.html?role='+role">增加裁判
                        </el-link>
                    </el-menu-item>
                </el-submenu>
                <el-submenu index="4">
                    <template slot="title">比赛项目管理</template>
                    <el-menu-item index="4-1">
                        <el-link
                                :href="'itemList.html?role='+role">比赛项目列表
                        </el-link>
                    </el-menu-item>
                    <el-menu-item index="4-2" v-if="role==0">
                        <el-link
                                :href="'itemAdd.html?role='+role">增加比赛项目
                        </el-link>
                    </el-menu-item>
                </el-submenu>
                <el-submenu index="5">
                    <template slot="title">场地管理</template>
                    <el-menu-item index="5-1">
                        <el-link
                                :href="'GroundList.html?role='+role">场地列表
                        </el-link>
                    </el-menu-item>
                    <el-menu-item index="5-2" v-if="role==0">
                        <el-link
                                :href="'GroundAdd.html?role='+role">增加场地
                        </el-link>
                    </el-menu-item>
                </el-submenu>
                <el-submenu index="6">
                    <template slot="title">留言管理</template>
                    <el-menu-item index="6-1">
                        <el-link
                                :href="'commentList.html?role='+role">留言查询
                        </el-link>
                    </el-menu-item>
                </el-submenu>
                <el-submenu index="7">
                    <template slot="title">报名管理</template>
                    <el-menu-item index="7-1">
                        <el-link
                                :href="'registerList.html?role='+role">报名查询
                        </el-link>
                    </el-menu-item>
                    <el-menu-item index="7-2" v-if="role==2">
                        <el-link
                                :href="'registerAdd.html?role='+role">报名
                        </el-link>
                    </el-menu-item>
                    <el-menu-item index="7-3" v-if="role==0 || role ==1">
                        <el-link
                                :href="'registerListAll.html?role='+role">报名审批
                        </el-link>
                    </el-menu-item>
                </el-submenu>
                <el-submenu index="8">
                    <template slot="title">成绩管理</template>
                    <el-menu-item index="8-1">
                        <el-link @click="dialogAthletes=true">查询成绩</el-link>
                    </el-menu-item>
                    <el-menu-item index="8-2" v-if="role==0 || role ==1">
                        <el-link @click="dialogItems=true">录入成绩</el-link>
                    </el-menu-item>
                    <el-menu-item index="8-3" v-if="role==2">
                        <el-link @click="dialogItems=true">根据项目查询成绩</el-link>
                    </el-menu-item>
                </el-submenu>
                <el-submenu index="9">
                    <template slot="title">个人中心</template>
                    <el-menu-item index="9-1" @click="logout">退出</el-menu-item>
                    <el-menu-item index="9-2" @click="userEdit(id)">编辑</el-menu-item>
                </el-submenu>
            </el-menu>
        </el-col>
    </el-row>

    <el-row :gutter="10" style="margin-bottom: 10px">
        <el-col :span="6">
            <el-button v-if="role == 2" type="primary" size="mini" @click="commentDialog.isShow = true">我要留言</el-button>
        </el-col>
        <el-col :span="18">
            <el-row>
                <div style="display: flex; align-items: center;">
                    <el-input placeholder="运动员姓名" v-model="name"
                              style="width: 500px; margin-right: 10px;"></el-input>
                    <el-button type="primary" @click="getComment">查询留言</el-button>
                </div>
            </el-row>
        </el-col>
    </el-row>


    <el-table :data="tableData" style="width: 100%; margin-bottom: 10px;" border stripe
              style="width: 100%">
        <!--              @selection-change="handleSelectionChange" style="width: 100%">-->

        <el-table-column prop="content" label="评论" align="center">
        </el-table-column>
        <el-table-column prop="athletesName" label="用户" align="center">
        </el-table-column>
        <el-table-column label="操作" v-if="role === 0">
            <template slot-scope="scope">
                <el-button
                        size="mini"
                        @click="edit(scope.row)">编辑
                </el-button>
                <el-button
                        size="mini"
                        type="danger"
                        @click="removeComment(scope.row.commentsId)">删除
                </el-button>
            </template>
        </el-table-column>
    </el-table>

    <!-- ************************编辑或添加评论对话框***************************** -->
    <el-dialog :title="commentDialog.title" :visible.sync="commentDialog.isShow" width="30%">

        <el-form>
            <el-form-item label="评论">
                <el-input v-model="comment.content" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>

        <!--        <el-form-item label="评论">
                    <el-input v-model="comment.content"></el-input>
                </el-form-item>-->
        <el-button @click="commentDialog.isShow = false">取 消</el-button>
        <el-button type="primary" @click="addAndUpdateComment">确 定</el-button>
    </el-dialog>

    <el-dialog title="提示" :visible.sync="dialogItems" width="30%">
        <el-form ref="form" :model="scaaa" label-width="80px">
            <el-form-item label="项目名">
                <el-input v-model="scaaa.itemName" placeholder="请输入项目名"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="showByItemName">查询</el-button>
                <el-button @click="dialogItems=false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>

    <!--    查询成绩-->
    <el-dialog title="提示" :visible.sync="dialogAthletes" width="30%">
        <el-form ref="form" :model="scaaa" label-width="80px">
            <el-form-item label="运动员名">
                <el-input v-model="scaaa.athletesName" placeholder="请输入运动员名"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="showByAthletesName">查询</el-button>
                <el-button @click="dialogAthletes=false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</div>
<script type="text/javascript">
    new Vue({
        el: "#app",
        data: {
            id: -1,
            activeIndex: "6-1",
            tableData: [],
            name: null,
            dialogAthletes: false,
            dialogItems: false,
            scaaa: { // 为了在顶部的成绩管理弹出对话框
                athletesName: "",
                itemName: ""
            },
            role: null,
            comment: {
                // athletesName: null,
                commentsId: null,
                content: null,
                createDate: null,
                userId: null
            },
            commentDialog: {
                title: "提示",
                isShow: false,
            },
            userId: null
        },
        created() {
            this.getCurrentUser();
            let queryString = window.location.search;
            let urlParams = new URLSearchParams(queryString);
            // this.role = urlParams.get('role');
            this.getComment();
            axios.get('user/getUser').then(res =>{
                if(res.data.role === 0){
                    this.id=res.data.user.adminId
                } else if(res.data.role === 1){
                    this.id=res.data.user.judgeId
                } else if(res.data.role === 2){
                    this.id=res.data.user.athletesId
                }
            })
        },
        methods: {
            showByAthletesName() {
                location.href = "sc111.html?athletesName=" + this.scaaa.athletesName + "&role=" + this.role
            },
            getCurrentUser() {
                axios.get('/user/getUser').then(res => {
                    if (res.status === 200) {
                        if (res.data.role === 0) { // 管理员
                            this.userId = res.data.user.adminId;
                        } else if (res.data.role === 1) { // 裁判
                            this.userId = res.data.user.judgeId;
                        } else if (res.data.role === 2) { // 裁判
                            this.userId = res.data.user.athletesId;
                        }
                        this.role = res.data.role;
                    }
                });
            },
            userEdit(id) {
                location.href = "athletesUpdate.html?id=" + id + "&role=" + this.role;
            },
            showByItemName() {
                location.href = "sc222.html?itemName=" + this.scaaa.itemName + "&role=" + this.role
            },
            logout() {
                axios.get('http://localhost:8080/user/logout')
                    .then(resp => {
                        if (resp.data.message == 'success') {
                            alert(resp.data.message)
                            location.href = 'login.html';
                        } else {
                            alert(resp.data.message)
                        }
                    }).catch(error => console.log(error))
            },
            // 获取所有评论
            getComment() {
                axios.get('/comment', {
                    params: {
                        athletesName: this.name
                    }
                }).then(res => {
                    if (res.status === 200) {
                        if (res.data.code === 200) {
                            this.tableData = res.data.data
                        }
                    }
                })
            },
            addAndUpdateComment() {
                this.comment.userId = this.userId;
                console.log(this.comment);
                axios.post('comment', this.comment).then(res => {
                    if (res.status === 200) {
                        this.$message({
                            message: '操作成功',
                            type: 'success'
                        });
                        this.getComment();
                        this.comment = {
                            commentsId: null,
                            content: null,
                            createDate: null,
                            userId: null
                        };
                        this.commentDialog.isShow = false;
                    }
                });
            },
            removeComment(id) {
                axios.delete('comment/' + id).then(res => {
                    if (res.status === 200) {
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        this.getComment();
                    }
                })
            },
            edit(obj) {
                this.comment = obj;
                this.commentDialog.isShow = true;
            }
        }
    })
</script>
</body>

</html>